package com.gzhryc.common;

import com.gzhryc.common.logging.Logger;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ScriptableObject;

public class JavascriptRhinoTools {

    static Logger log = Logger.getLogger(JavascriptRhinoTools.class);

    public static Object eval(String script) {
        Context context = Context.enter();
        try {
            ScriptableObject engine = context.initSafeStandardObjects();
            return context.evaluateString(engine,"(function(){"+script+"})();","JavaScript",1,null);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }finally {
            Context.exit();
        }
        return null;
    }
}
